package CreativePattern.PrototypePattern;

import CreativePattern.PrototypePattern.entity.Contact;
import CreativePattern.PrototypePattern.entity.User;
//原型模式
public class TestPrototype {
    public static void main(String[] args) {
        // 创建一个用户实例‘
        Contact contact = new Contact("广东", "15899886699");
        User user1 = new User("Alice", 30, "Female",contact);
        System.out.println("Original: " + user1);

        // 克隆用户
        User clonedUser1 = user1.clone();
        System.out.println("Cloned:   " + clonedUser1);

        System.out.println("-------------------------------");

        // 修改原型的字段以验证克隆的独立性
        user1.setName("Bob");
        user1.setAge(25);
        user1.setSex("Male");
            contact.setAddress("海南");
            contact.setPhone("18999886699");

        System.out.println("Modified Original:\n          " + user1);
        System.out.println("Cloned after modification:\n          " + clonedUser1);
    }
}
